package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.logistic.domain.NetworkHqPreFeeName;
import com.ruoyi.logistic.domain.NetworkHqPreMyAccount;
import com.ruoyi.logistic.domain.NetworkHqPrePayment;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkHqPrePaymentVo;
import com.ruoyi.logistic.enums.NetworkHqPrePaymentEnum;
import com.ruoyi.logistic.mapper.NetworkHqPreFeeNameMapper;
import com.ruoyi.logistic.mapper.NetworkHqPreMyAccountMapper;
import com.ruoyi.logistic.mapper.NetworkHqPrePaymentMapper;
import com.ruoyi.logistic.service.NetworkHqPrePaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class NetworkHqPrePaymentServiceImpl implements NetworkHqPrePaymentService {
    @Autowired
    private NetworkHqPrePaymentMapper networkHqPrePaymentMapper;
    @Autowired
    private NetworkHqPreMyAccountMapper networkHqPreMyAccountMapper;
    @Autowired
    private NetworkHqPreFeeNameMapper  networkHqPreFeeNameMapper;
    @Override
    public List<NetworkHqPrePayment> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkHqPrePaymentMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkHqPrePayment networkHqPrePayment) {
        return networkHqPrePaymentMapper.insert(networkHqPrePayment);
    }

    @Override
    public Boolean update(NetworkHqPrePayment networkHqPrePayment) {
        return networkHqPrePaymentMapper.update(networkHqPrePayment);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkHqPrePaymentMapper.deleteById(id);
    }

    @Override
    public List<NetworkHqPrePayment> search(NetworkHqPrePaymentVo networkHqPrePaymentVo) {
        PageHelper.startPage(networkHqPrePaymentVo.getPageDate());
        return networkHqPrePaymentMapper.search(networkHqPrePaymentVo);
    }

    @Override
    public List<NetworkHqPreMyAccount> myAccount(String networkNameId) {
        return networkHqPreMyAccountMapper.search(networkNameId);
    }

    @Override
    public List<NetworkHqPreFeeName> selectAll() {
        return networkHqPreFeeNameMapper.selectAll();
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"networkNameId", "businessTime", "chargeTime", "businessId", "businessSummary", "feeName"
                , "income", "expend", "balance","connectionWay","billType","associatedAccount"
                , "bankAccount"
        };
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkHqPrePaymentEnum.getValue(vo.getFields()));
        }
        return list;
    }
}
